home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / egem_200.lzh / EGEM.2_0 / SOURCE / SCRAP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-07  |  2.4 KB  |  148 lines

  1.  
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include "proto.h"
  5.  
  6. int    scrp_init(char *path)
  7. {
  8.     reg char scrap[256];
  9.     reg long handle,len;
  10.  
  11.     scrp_read(scrap);
  12.     if (scrap[0]=='\0')
  13.     {
  14.         if (path)
  15.             strcpy(scrap,path);
  16.         else if ((path = getenv("CLIPBRD"))!=NULL || (path = getenv("SCRAPDIR"))!=NULL)
  17.             strcpy(scrap,path);
  18.         else
  19.         {
  20.             reg long ssp;
  21.  
  22.             strcpy(scrap,"X:\\CLIPBRD");
  23.             ssp = Super(NULL);
  24.             *scrap = (char) (*((int *) 0x446)+65);
  25.             Super((void *) ssp);
  26.         }
  27.     }
  28.  
  29.     if ((len = strlen(scrap))>0)
  30.     {
  31.         len--;
  32.         if (scrap[len]=='\\')
  33.             scrap[len]='\0';
  34.  
  35.         handle = Dcreate(scrap);
  36.         if (handle>=0 || handle==-36)
  37.         {
  38.             scrp_write(strcat(scrap,"\\"));
  39.             return(TRUE);
  40.         }
  41.     }
  42.  
  43.     scrp_write("");
  44.     return(FALSE);
  45. }
  46.  
  47. void scrp_clear(int all)
  48. {
  49.     reg char scrap[256];
  50.  
  51.     scrp_read(scrap);
  52.     if (scrap[0]!='\0')
  53.     {
  54.         reg DTA *dta=Fgetdta();
  55.         reg char xpath[256],xname[256];
  56.  
  57.         _strmfp(xpath,scrap,(all) ? "*.*" : "SCRAP.*");
  58.         if (!Fsfirst(xpath,0))
  59.             do
  60.             {
  61.                 _strmfp(xname,scrap,dta->d_fname);
  62.                 remove(xname);
  63.             }
  64.             while (!Fsnext());
  65.         scrp_changed(SCF_INDEF,0l);
  66.     }
  67. }
  68.  
  69. long    scrp_length()
  70. {
  71.     reg char scrap[256];
  72.  
  73.     scrp_read(scrap);
  74.     if (scrap[0]!='\0')
  75.     {
  76.         reg DTA *dta=Fgetdta();
  77.         reg char xpath[256];
  78.  
  79.         _strmfp(xpath,scrap,"SCRAP.*");
  80.         if (!Fsfirst(xpath,0))
  81.         {
  82.             reg long length = 0;
  83.             do
  84.                 length += dta->d_length;
  85.             while (!Fsnext());
  86.             return (length);
  87.         }
  88.     }
  89.  
  90.     return (0);
  91. }
  92.  
  93. int    scrp_find(char *extension,char *filename)
  94. {
  95.     reg char scrap[256];
  96.  
  97.     scrp_read(scrap);
  98.     if (scrap[0]!='\0')
  99.     {
  100.         reg DTA  *dta=Fgetdta();
  101.         reg char xpath[256];
  102.         reg int  c = 0;
  103.  
  104.         strcat(_strmfp(xpath,scrap,"SCRAP."),extension);
  105.         if(!Fsfirst(xpath,0))
  106.         {
  107.             c++;
  108.             _strmfp(filename,scrap,dta->d_fname);
  109.             while (!Fsnext()) c++;
  110.             return (c);
  111.         }
  112.     }
  113.     return (0);
  114. }
  115.  
  116. void scrp_changed(int format,long best_ext)
  117. {
  118.     int msg[8];
  119.  
  120.     msg[0] = SC_CHANGED;
  121.     msg[3] = format;
  122.     msg[4] = (int) (best_ext>>16);
  123.     msg[5] = (int) best_ext;
  124.     msg[6] = msg[7] = 0;
  125.     XAccBroadCast(msg);
  126. }
  127.  
  128. char *_strmfp(char *dest,char *path,char *file)
  129. {
  130.     reg char *last;
  131.     reg int len;
  132.  
  133.     if (path)
  134.         strcpy(dest,path);
  135.  
  136.     if ((len = (int) strlen(dest))>0)
  137.     {
  138.         last = dest + len - 1;
  139.         if (*last!='\\')
  140.         {
  141.             *++last = '\\';
  142.             *++last = '\0';
  143.         }
  144.     }
  145.  
  146.     return(strcat(dest,file));
  147. }
  148.